/**
 * Copyright (C) 2011 KingCore Science & Technology CO,.LTD. All rights reserved.
 * XNS PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

/**
 * Copyright (C) 2002-2011 WUZEWEN. All rights reserved.
 * WUZEWEN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 * This software is the confidential and proprietary information of
 * WuZeven, Personal. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with WuZeven.
 */

package wzw.swing.table;

import java.awt.Color;
import java.awt.Component;
import java.io.File;

import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.filechooser.FileSystemView;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

import wzw.util.ComponentUtil;

import com.kingcore.director.DirectorConstants;

/**
 * <p>java类文件的说明...</p>
 * @author Zeven/wzw on Mar 18, 2011
 * @version	1.0
 * @see		Object#equals(java.lang.Object)
 * @since	JDK5
 */

public class IconTableCellRenderer extends DefaultTableCellRenderer implements TableCellRenderer{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTable mainTable = null;
	private int columnIndex ;
	private boolean showZebraCross = false;
	
	public IconTableCellRenderer(JTable mainTable,
			int column_Index, boolean showZebraCross ) {
		super();
		this. mainTable = mainTable;
		this.columnIndex = column_Index;
		this.showZebraCross = showZebraCross;
	}
	
	/**
	 * <p>java方法的说明...</p>
	 * @author Zeven on Mar 18, 2011
	 * @param args
	 */
	public static void main(String[] args) {

	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		// File f = new File(value.toString());
		String fileUri = mainTable.getModel().getValueAt(row, columnIndex)
				.toString();
		File f = new File(fileUri);
		JLabel label = null;
		if (f.exists()) {
			Icon icon = FileSystemView.getFileSystemView().getSystemIcon(f);
			label = new JLabel(value.toString(), icon, JLabel.LEFT);
			// System.out.println(f.getPath());

		} else {
			label = new JLabel(value.toString(), JLabel.LEFT);
		}
		label.setOpaque(true);  //配合斑马线
		// step:选中否
		if (isSelected) {
			label.setBackground(table.getSelectionBackground());
			if(ComponentUtil.getNimbusLookAndFeelClassName().equals( UIManager.getLookAndFeel().getClass().getName() )){
				label.setForeground(Color.WHITE); //getForeground()); special for Nimbus style
			}
		} else {
			// step:斑马线
			if (this.showZebraCross) {
				if (row % 2 == 1)// JTable中的奇数行
				{
					label.setBackground( DirectorConstants.Color_ZebraCross );
				} else {
					label.setBackground(Color.WHITE);
				}

			}
		} 
		
//		super.getTableCellRendererComponent(table, value,
//				isSelected, hasFocus, row, column);
		return label;
	}
}
